/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.suspend.b.e;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class b {
    public static boolean a(File paramFile) {
        if (paramFile == null)
            return false;
        try {
            if (paramFile.isDirectory())
                b(paramFile);
        } catch (Exception localException1) {}
        try {
            return paramFile.delete();
        } catch (Exception localException2) {}
        return false;
    }

    public static void b(File paramFile) {
        if (!(paramFile.exists())) {
            localObject1 = paramFile + " does not exist";
            throw new IllegalArgumentException((String) localObject1);
        }
        if (!(paramFile.isDirectory())) {
            localObject1 = paramFile + " is not a directory";
            throw new IllegalArgumentException((String) localObject1);
        }
        Object localObject1 = paramFile.listFiles();
        if (localObject1 == null)
            throw new IOException("Failed to list contents of " + paramFile);
        Object localObject2 = null;
        for (File localFile : localObject1)
            try {
                c(localFile);
            } catch (IOException localIOException) {
                localObject2 = localIOException;
            }
        if (localObject2 == null)
            return;
        throw localObject2;
    }

    public static void c(File paramFile) {
        if (paramFile.isDirectory()) {
            d(paramFile);
        }
        else {
            boolean bool = paramFile.exists();
            if (paramFile.delete())
                return;
            if (!(bool))
                throw new FileNotFoundException("File does not exist: " + paramFile);
            String str = "Unable to delete file: " + paramFile;
            throw new IOException(str);
        }
    }

    public static void d(File paramFile) {
        if (!(paramFile.exists()))
            return;
        if (!(e(paramFile)))
            b(paramFile);
        if (paramFile.delete())
            return;
        String str = "Unable to delete directory " + paramFile + ".";
        throw new IOException(str);
    }

    public static void a(File paramFile1, File paramFile2) {
        if (paramFile1 == null)
            throw new NullPointerException("Source must not be null");
        if (paramFile2 == null)
            throw new NullPointerException("Destination must not be null");
        if (!(paramFile1.exists()))
            throw new FileNotFoundException("Source '" + paramFile1 + "' does not exist");
        if (paramFile1.isDirectory())
            throw new IOException("Source '" + paramFile1 + "' is a directory");
        if (paramFile2.exists())
            throw new IOException("Destination '" + paramFile2 + "' already exists");
        if (paramFile2.isDirectory())
            throw new IOException("Destination '" + paramFile2 + "' is a directory");
        boolean bool = paramFile1.renameTo(paramFile2);
        if (bool)
            return;
        b(paramFile1, paramFile2);
        if (paramFile1.delete())
            return;
        a(paramFile2);
        throw new IOException("Failed to delete original file '" + paramFile1 + "' after copy to '" + paramFile2 + "'");
    }

    public static void b(File paramFile1, File paramFile2) {
        a(paramFile1, paramFile2, true);
    }

    public static void a(File paramFile1, File paramFile2, boolean paramBoolean) {
        if (paramFile1 == null)
            throw new NullPointerException("Source must not be null");
        if (paramFile2 == null)
            throw new NullPointerException("Destination must not be null");
        if (!(paramFile1.exists()))
            throw new FileNotFoundException("Source '" + paramFile1 + "' does not exist");
        if (paramFile1.isDirectory())
            throw new IOException("Source '" + paramFile1 + "' exists but is a directory");
        if (paramFile1.getCanonicalPath().equals(paramFile2.getCanonicalPath()))
            throw new IOException("Source '" + paramFile1 + "' and destination '" + paramFile2 + "' are the same");
        if ((paramFile2.getParentFile() != null) && (!(paramFile2.getParentFile().exists()))
                && (!(paramFile2.getParentFile().mkdirs())))
            throw new IOException("Destination '" + paramFile2 + "' directory cannot be created");
        if ((paramFile2.exists()) && (!(paramFile2.canWrite())))
            throw new IOException("Destination '" + paramFile2 + "' exists but is read-only");
        b(paramFile1, paramFile2, paramBoolean);
    }

    private static void b(File paramFile1, File paramFile2, boolean paramBoolean) {
        if ((paramFile2.exists()) && (paramFile2.isDirectory()))
            throw new IOException("Destination '" + paramFile2 + "' exists but is a directory");
        FileInputStream localFileInputStream = null;
        FileOutputStream localFileOutputStream = null;
        FileChannel localFileChannel1 = null;
        FileChannel localFileChannel2 = null;
        try {
            localFileInputStream = new FileInputStream(paramFile1);
            localFileOutputStream = new FileOutputStream(paramFile2);
            localFileChannel1 = localFileInputStream.getChannel();
            localFileChannel2 = localFileOutputStream.getChannel();
            long l1 = localFileChannel1.size();
            long l2 = 0L;
            long l3 = 0L;
            while (l2 < l1) {
                l3 = (l1 - l2 > 52428800L) ? 52428800L : l1 - l2;
                l2 += localFileChannel2.transferFrom(localFileChannel1, l2, l3);
            }
        } finally {
            d.a(localFileChannel2);
            d.a(localFileOutputStream);
            d.a(localFileChannel1);
            d.a(localFileInputStream);
        }
        if (paramFile1.length() != paramFile2.length())
            throw new IOException("Failed to copy full contents from '" + paramFile1 + "' to '" + paramFile2 + "'");
        if (!(paramBoolean))
            return;
        paramFile2.setLastModified(paramFile1.lastModified());
    }

    public static boolean e(File paramFile) {
        if (paramFile == null)
            throw new NullPointerException("File must not be null");
        if (c.a())
            return false;
        File localFile1 = null;
        if (paramFile.getParent() == null) {
            localFile1 = paramFile;
        }
        else {
            File localFile2 = paramFile.getParentFile().getCanonicalFile();
            localFile1 = new File(localFile2, paramFile.getName());
        }
        return (!(localFile1.getCanonicalFile().equals(localFile1.getAbsoluteFile())));
    }
}